 <%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="java.io.*,control.database.*"%>
<HTML><HEAD><TITLE>推荐人查询</TITLE>

<LINK href="Default.files/css.css" type=text/css rel=stylesheet>

<SCRIPT src="fPopUpCalendarDlg.js"></SCRIPT>
<% 
request.setCharacterEncoding("gb2312");
String section="0";
 section=(String)session.getAttribute("mger_code");
 String domainName=(String)session.getAttribute("mger_hostname");
%>
<SCRIPT language=javascript>
function check(){

	option.submit();
	return true;
	}
	



</SCRIPT>
</HEAD>
<BODY >

<%


String requestName="";

  if((request.getParameter("areacode")!=null))
  {
  section=request.getParameter("areacode");
  }
  %>

<FORM name=option action="request_query.jsp" method=post> 
   
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD vAlign=top align="center" colSpan=2>
							<TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#f1f1f1 border=0>
								<TBODY>
									<TR height=40>
										<TD width="24%">
											<FONT color="#00ff80">
												<FONT color="#8000ff">
													 推荐人查询												</FONT>											</FONT>										</TD>
										
										<TD width="64%" >
		 <%if(((String)session.getAttribute("mger_code")).equals("0")){%>
		 
		 <select name="areacode" size=1>
           <%
          		DataBase db=new DataBase();
          		ResultSet rst=db.executeQuery("select * from mz_areacode where areaid=2 order by sortid");
          		while(rst.next()){
          %>
            <option value="<%=rst.getString("areacode")%>" <%if(section.equals(rst.getString("areacode")))out.print("selected");%>><%out.print(rst.getString("areaname"));%> </option>
            <%}
            rst.close();
            db.closeStmt();
	    	db.closeConn();
            
            %></select>
            <%}%>
             会员类型<select name="user_type" class=9pt style="WIDTH: 70px">
                    <option value='10' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("10")))out.print("selected");%>><%out.print("(全部)");%></option>
                    <option value='PHS' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("PHS")))out.print("selected");%>><%out.print("小灵通");%></option>
                    <option value='PSTN' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("PSTN")))out.print("selected");%>><%out.print("固话");%></option>
                    <!-- option value='NET' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("NET")))out.print("selected");%>><%out.print("宽带");%></option-->
                    </select>
					状态
			<select name="state">
			   <option value="10" <%if((request.getParameter("state")!=null)&&(request.getParameter("state").equals("10")))out.print("selected");%>>(全部)</option>
               <option value="1" <%if((request.getParameter("state")!=null)&&(request.getParameter("state").equals("1")))out.print("selected");%>>正常</option>
               <option value="7" <%if((request.getParameter("state")!=null)&&(request.getParameter("state").equals("7")))out.print("selected");%>>注销</option>
               <option value="0" <%if((request.getParameter("state")!=null)&&(request.getParameter("state").equals("0")))out.print("selected");%>>暂停</option>
             </select>
           
             推荐人号码<INPUT style="WIDTH: 90px" type="text" name=requestName value=<%if(request.getParameter("requestName")!=null)out.print(request.getParameter("requestName"));%> ></TD>
            <td width="12%"><INPUT type=button name=tongji value="查询" onClick="return check()"></TD>
           
          
									</TR>
								</TBODY>
							</TABLE>
							<%	
							 String sql="";
							requestName=request.getParameter("requestName");
						//	out.println("^^^^^"+requestName);
							if(request.getParameter("today")!=null){%>
							
						<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
								<TBODY>
									<TR>
										<TD>
											<TABLE id=dgDownLoad style="BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; BORDER-COLLAPSE: collapse; BORDER-RIGHT-COLOR: #cccccc" borderColor=#cccccc cellSpacing=0 rules=all border=1>
												<TBODY>
												
												 <TR style="BACKGROUND-COLOR:#d0ebee" align="center">
													     <TD style="WIDTH: 8%">
															<FONT color="#ff0080">注册日期</FONT>
														</TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">地区名</FONT>
														</TD>
														
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">号码总数

														</FONT></TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">号码下载
														</FONT></TD>
														
													</TR>     
													
												</TBODY>
											</TABLE>
										</TD>
									</TR>
								</TBODY>
							</TABLE>
							<%
							}
							else{
							if((request.getParameter("requestName")==null)||(request.getParameter("requestName").length()<1)){
							%>
							
						<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0>
								<TBODY>
									<TR>
										<TD>
											<TABLE id=dgDownLoad style="BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; BORDER-COLLAPSE: collapse; BORDER-RIGHT-COLOR: #cccccc" borderColor=#cccccc cellSpacing=0 rules=all border=1>
												<TBODY>
												
												 <TR style="BACKGROUND-COLOR:#d0ebee" align="center">
													     <TD style="WIDTH: 8%">
															<FONT color="#ff0080">注册日期</FONT>
														</TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">地区名</FONT>
														</TD>
														
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">号码总数

														</FONT></TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">号码下载
														</FONT></TD>
														
													</TR>

													<%
						
						if(!request.getParameter("state").equals("10"))
						sql="select b.areaname,a.num,b.areacode from (select  substring(username,1,4) as areacode,count(username)as num from  users a where domainName='"+domainName+"' and state='"+request.getParameter("state")+"' group by  substring(username,1,4)  )a,mz_areacode b where a.areacode=b.areacode and b.areaid=2 order by b.sortid";							   
                   else
                     sql="select b.areaname,a.num,b.areacode from (select   substring(username,1,4) as areacode,count(username)as num from  users a where domainName='"+domainName+"' group by  substring(username,1,4) )a,mz_areacode b where a.areacode=b.areacode and b.areaid=2 order by b.sortid";


							
						if((request.getParameter("user_type")!=null)&&(!request.getParameter("user_type").equals("10"))){
								if(!request.getParameter("state").equals("10")){
												sql="select b.areaname,a.num,b.areacode from (select  substring(username,1,4) as areacode,count(username)as num from  users a where domainName='"+domainName+"' and state='"+request.getParameter("state")+"' and user_type='"+request.getParameter("user_type")+"' group by  substring(username,1,4)  )a,mz_areacode b where a.areacode=b.areacode and b.areaid=2 order by b.sortid";
								}else
								{		
												sql="select b.areaname,a.num,b.areacode from (select  substring(username,1,4) as areacode,count(username)as num from  users a where domainName='"+domainName+"' and user_type='"+request.getParameter("user_type")+"' group by  substring(username,1,4)  )a,mz_areacode b where a.areacode=b.areacode and b.areaid=2 order by b.sortid";

								}
												
												}
												//out.println(sql);
													Context initCtx = new InitialContext();
												    Context envCtx = (Context) initCtx.lookup("java:comp/env");
												    DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");  
				                                   Connection conn = ds.getConnection();
												    Statement stmt = conn.createStatement();
												  //  Statement stmt2 = conn.createStatement();
													ResultSet rst = stmt.executeQuery(sql);
													
													while(rst.next()){
													%> <TR  align="center">
													<TD style="WIDTH: 7%" align=left>
																<FONT color="#8080ff">
																<%
																//if((request.getParameter("year")!=null)&&(!request.getParameter("year").equals("1000"))&&(request.getParameter("month")!=null)&&(!request.getParameter("month").equals("0001")))

																//{
																//out.println(monthtime.substring(0,4)+"年"+monthtime.substring(4,6)+"月");
																//}
																//else {
																
																out.println("无时间范围限制");
																//}
												                  %>
																</FONT>
														
													</TD>
													<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
                                                 out.println(rst.getString("areaname"));
								                              
																%>
																</FONT>
														
														</TD>

														<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
																out.println(rst.getString("num"));
																%>
																</FONT>
														
														</TD>
														<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
															if((rst.getString("areacode").trim().equals(section))||(section.equals("0"))){
															%>
															<a target="-blank" href="requestNameDown.jsp?areacode=<%=rst.getString("areacode").trim()%>&monthtime=<%="10000001"%>">号码下载</a>
															<%
															}
															else{
															out.println("无权下载");
															}
																%>
																</FONT>
														
														</TD>
													
														
														
													</TR><%
													//out.println(rst.getString("num"));
													}
													rst.close();
													stmt.close();
													conn.close();
											
												
												%>
													     
													     
													
												</TBODY>
											</TABLE>
										</TD>
									</TR>
								</TBODY>
							</TABLE>
							<%}else{%>
							<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0>
								<TBODY>
									<TR>
										<TD>
											<TABLE id=dgDownLoad style="BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; BORDER-COLLAPSE: collapse; BORDER-RIGHT-COLOR: #cccccc" borderColor=#cccccc cellSpacing=0 rules=all border=1>
												<TBODY>
												
												 
													<TR style="BACKGROUND-COLOR:#d0ebee" align="center">
													     <TD style="WIDTH: 8%">
															<FONT color="#ff0080">用户号码</FONT>
														</TD>
														
														
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">业务类型

														</FONT></TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">注册日期
														</FONT></TD>
														<TD style="WIDTH: 5%">
															<FONT color="#ff0080">推荐人号码


														</FONT></TD>
													</TR>
												<%
                       
                       sql="select username,grade,createdDate,requestName from users where username like '"+section+"%' and domainName='"+domainName+"' and requestName='"+requestName+"'";
												if((request.getParameter("user_type")!=null)&&(!request.getParameter("user_type").equals("10"))){
												sql+=" and user_type='"+request.getParameter("user_type")+"'";
												}
												if((request.getParameter("state")!=null)&&(!request.getParameter("state").equals("10"))){
												sql+=" and state='"+request.getParameter("state")+"'";
												}
										
												
													Context initCtx = new InitialContext();
												    Context envCtx = (Context) initCtx.lookup("java:comp/env");
												    DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");  
				                                   Connection conn = ds.getConnection();
												    Statement stmt = conn.createStatement();
													ResultSet rst = stmt.executeQuery(sql);
													
													while(rst.next()){
													%>
												
													<TR  align="center">
													<TD style="WIDTH: 7%" align=left>
																<FONT color="#8080ff">
																<%
															out.println(rst.getString("username"));
												                  %>
																</FONT>
														
													</TD>
													<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
                                                               if(rst.getString("grade").equals("1"))
								                             out.println("普通用户");
								                             else if(rst.getString("grade").equals("2"))
								                             out.println("商务用户");
								                             else if(rst.getString("grade").equals("3"))
								                             out.println("精英用户");
								                             else if(rst.getString("grade").equals("8"))
								                             out.println("特惠用户");
																%>
																</FONT>
														
														</TD>

														<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
																out.println(rst.getString("createdDate"));
																%>
																</FONT>
														
														</TD>
														<TD style="WIDTH: 5%" align=left>
																<FONT color="#8080ff">
																<%
															out.println(rst.getString("requestName"));
																%>
																</FONT>
														
														</TD>
													
														
														
													</TR>

													<%}
													rst.close();
													stmt.close();
													conn.close();
											
												
												%>


												</TBODY>
											</TABLE>
										</TD>
									</TR>
								</TBODY>
								
							</TABLE>
							<%}}
							%>
						</TD></TR>
  <TR>
    <TD height=20>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
        <TBODY>
        <TR>
          <!-- TD width=180><IMG height=40 
            src="Default.files/main_bottom_pic01.gif" width=180></TD-->
          <TD width="40%" background=Default.files/main_bottom_bg.gif></TD>
          <TD align=right background=Default.files/main_bottom_bg.gif>
            </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></BODY></HTML>
